﻿/**
 * 通用js方法封装处理
 * Copyright (c) 2019 ruoyi
 */

const baseURL = process.env.VUE_APP_BASE_API
// export function getMonth(type, monthss) {
//   let months = 0
//   if (type == "s") {
//     months = -1
//   } else {
//     months = 0
//   }
//   var d = new Date();
//   var year = d.getFullYear();
//   var month = d.getMonth() + 1;
//   if (Math.abs(months) > 12) {
//     months = months % 12;
//   }
//   if (months != 0) {
//     if (month + months > 12) {
//       year++;
//       month = (month + months) % 12;
//     } else if (month + months < 1) {
//       year--;
//       month = 12 + month + months;
//     } else {
//       month = month + months;
//     }
//   }
//   month = month < 10 ? "0" + month : month;
//   // var date = d.getDate();
//   var firstday = year + "-" + month + "-" + "27";
//   var lastday = "";
//   if (
//     month == "01" ||
//     month == "03" ||
//     month == "05" ||
//     month == "07" ||
//     month == "08" ||
//     month == "10" ||
//     month == "12"
//   ) {
//     lastday = year + "-" + month + "-" + 26;
//   } else if (month == "02") {
//     if (
//       (year % 4 == 0 && year % 100 != 0) ||
//       (year % 100 == 0 && year % 400 == 0)
//     ) {
//       lastday = year + "-" + month + "-" + 26;
//     } else {
//       lastday = year + "-" + month + "-" + 26;
//     }
//   } else {
//     lastday = year + "-" + month + "-" + 26;
//   }
//   var day = "";
//   if (type == "s") {
//     day = firstday;
//   } else {
//     day = lastday;
//   }
//   return day;
// }
export function getMonth(type, monthss) {
  var d = new Date();
  var getYear = d.getFullYear();
  var getMonth = d.getMonth() + 1;
  var getDate = d.getDate();
  let year = d.getFullYear()
  let month = 0
  let date = 0
  if (type == 's') {
    date = 27
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '01'
      } else {
        month = '12'
        year = Number(d.getFullYear()) - 1
      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '02'
      } else {
        month = '01'
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '02'
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '04'
      } else {
        month = '03'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '05'
      } else {
        month = '04'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '05'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '07'
      } else {
        month = '06'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '08'
      } else {
        month = '07'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '08'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '10'
      } else {
        month = '09'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '11'
      } else {
        month = '10'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '11'
      }
    }
  } else {
    date = 26
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '02'
      } else {
        month = '01'

      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '02'
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '04'
      } else {
        month = '03'
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '05'
      } else {
        month = '04'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '05'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '07'
      } else {
        month = '06'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '08'
      } else {
        month = '07'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '08'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '10'
      } else {
        month = '09'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '11'
      } else {
        month = '10'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '11'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '01'
        year = Number(d.getFullYear()) + 1
      } else {
        month = '12'
      }
    }
  }
  var day = year + '-' + month + "-" + date
  return day;
}

export function getLastMonth(type, monthss) {
  var d = new Date();
  var getYear = d.getFullYear();
  var getMonth = d.getMonth() + 1;
  var getDate = d.getDate();
  let year = d.getFullYear()
  let month = 0
  let date = 0
  if (type == 's') {
    date = 27
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '12'
        year = Number(d.getFullYear()) - 1
      } else {
        month = '11'
        year = Number(d.getFullYear()) - 1
      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '01'
      } else {
        month = '12'
        year = Number(d.getFullYear()) - 1
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '02'
      } else {
        month = '01'
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '02'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '04'
      } else {
        month = '03'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '05'
      } else {
        month = '04'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '05'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '07'
      } else {
        month = '06'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '08'
      } else {
        month = '07'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '08'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '10'
      } else {
        month = '09'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '11'
      } else {
        month = '10'
      }
    }
  } else {
    date = 26
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '01'

      } else {
        month = '12'
        year = Number(d.getFullYear()) - 1

      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '02'
      } else {
        month = '01'
        // year = Number(d.getFullYear())
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '02'
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '04'
      } else {
        month = '03'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '05'
      } else {
        month = '04'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '05'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '07'
      } else {
        month = '06'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '08'
      } else {
        month = '07'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '08'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '10'
      } else {
        month = '09'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '11'
      } else {
        month = '10'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '11'
      }
    }
  }
  var day = year + '-' + month + "-" + date
  return day;
}
export function getMonth2(type, monthss) {
  let months = 0
  if (monthss) {
    months = monthss
  } else {
    months = 0
  }
  var d = new Date();
  var year = d.getFullYear();
  var month = d.getMonth() + 1;
  if (Math.abs(months) > 12) {
    months = months % 12;
  }
  if (months != 0) {
    if (month + months > 12) {
      year++;
      month = (month + months) % 12;
    } else if (month + months < 1) {
      year--;
      month = 12 + month + months;
    } else {
      month = month + months;
    }
  }
  month = month < 10 ? "0" + month : month;
  var date = d.getDate();
  var firstday = year + "-" + month + "-" + "01";
  var lastday = "";
  if (
    month == "01" ||
    month == "03" ||
    month == "05" ||
    month == "07" ||
    month == "08" ||
    month == "10" ||
    month == "12"
  ) {
    lastday = year + "-" + month + "-" + 31;
  } else if (month == "02") {
    if (
      (year % 4 == 0 && year % 100 != 0) ||
      (year % 100 == 0 && year % 400 == 0)
    ) {
      lastday = year + "-" + month + "-" + 29;
    } else {
      lastday = year + "-" + month + "-" + 28;
    }
  } else {
    lastday = year + "-" + month + "-" + 30;
  }
  var day = "";
  if (type == "s") {
    day = firstday;
  } else {
    day = lastday;
  }
  return day;
}
export function getQuarterMonth2(type) {
  var now = new Date();
  var nowMonth = Number(now.getMonth()) + 1;
  var year = now.getFullYear();
  var quarterStartMonth = "01";
  if (nowMonth < 3) {
    quarterStartMonth = "01";
  }
  if (2 < nowMonth && nowMonth < 6) {
    quarterStartMonth = "04";
  }
  if (5 < nowMonth && nowMonth < 9) {
    quarterStartMonth = "07";
  }
  if (nowMonth > 8) {
    quarterStartMonth = "10";
  }
  var startDay = year + "-" + quarterStartMonth + "-01";
  var endDay = null;
  if (quarterStartMonth == "01") {
    endDay = year + "-03" + "-31";
  }
  if (quarterStartMonth == "10") {
    endDay = year + "-12" + "-31";
  }
  if (quarterStartMonth == "04") {
    endDay = year + "-06" + "-30";
  }
  if (quarterStartMonth == "07") {
    endDay = year + "-09" + "-30";
  }
  var day = "";
  if (type == "s") {
    day = startDay;
  } else {
    day = endDay;
  }
  return day;
}
// export function getQuarterMonth(type) {
//   var now = new Date();
//   var getMonth = Number(now.getMonth()) + 1;
//   var getYear = now.getFullYear();
//   var getDate = now.getDate()
//   let year = now.getFullYear()
//   let month = 0
//   let date = 0
//   if (type == 's') {
//     date = 27
//     if (getMonth == 1) {
//       if (getDate > 26) {
//         month = '12'
//       } else {
//         month = '12'
//         year = Number(now.getFullYear()) - 1
//       }
//     } else if (getMonth == 2) {
//       if (getDate > 26) {
//         month = '12'
//       } else {
//         month = '12'
//       }
//     } else if (getMonth == 3) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '12'
//       }
//     } else if (getMonth == 4) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '03'
//       }
//     } else if (getMonth == 5) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '03'
//       }
//     } else if (getMonth == 6) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 7) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 8) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 9) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 10) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 11) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 12) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '12'
//       }
//     }
//   } else {
//     date = 26
//     if (getMonth == 1) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '03'

//       }
//     } else if (getMonth == 2) {
//       if (getDate > 26) {
//         month = '03'
//       } else {
//         month = '03'
//       }
//     } else if (getMonth == 3) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '03'
//       }
//     } else if (getMonth == 4) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 5) {
//       if (getDate > 26) {
//         month = '06'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 6) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '06'
//       }
//     } else if (getMonth == 7) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 8) {
//       if (getDate > 26) {
//         month = '09'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 9) {
//       if (getDate > 26) {
//         month = '12'
//       } else {
//         month = '09'
//       }
//     } else if (getMonth == 10) {
//       if (getDate > 26) {
//         month = '12'
//       } else {
//         month = '12'
//       }
//     } else if (getMonth == 11) {
//       if (getDate > 26) {
//         month = '12'
//       } else {
//         month = '12'
//       }
//     } else if (getMonth == 12) {
//       if (getDate > 26) {
//         month = '03'
//         year = Number(now.getFullYear()) + 1
//       } else {
//         month = '12'
//       }
//     }
//   }
//   var day = year + '-' + month + "-" + date
//   return day;
// }

export function getQuarterMonth(type) {
  var now = new Date();
  var getMonth = Number(now.getMonth()) + 1;
  var getYear = now.getFullYear();
  var getDate = now.getDate()
  let year = now.getFullYear()
  let month = 0
  let date = 0
  if (type == 's') {
    date = 27
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '12'
        year = Number(now.getFullYear()) - 1
      } else {
        month = '12'
        year = Number(now.getFullYear()) - 1
      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '12'
        year = Number(now.getFullYear()) - 1
      } else {
        month = '12'
        year = Number(now.getFullYear()) - 1
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '12'
        year = Number(now.getFullYear()) - 1
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '03'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '03'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '03'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '06'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '06'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '06'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '09'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '09'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '09'
      }
    }
  } else {
    date = 26
    if (getMonth == 1) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '03'

      }
    } else if (getMonth == 2) {
      if (getDate > 26) {
        month = '03'
      } else {
        month = '03'
      }
    } else if (getMonth == 3) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '03'
      }
    } else if (getMonth == 4) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '06'
      }
    } else if (getMonth == 5) {
      if (getDate > 26) {
        month = '06'
      } else {
        month = '06'
      }
    } else if (getMonth == 6) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '06'
      }
    } else if (getMonth == 7) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '09'
      }
    } else if (getMonth == 8) {
      if (getDate > 26) {
        month = '09'
      } else {
        month = '09'
      }
    } else if (getMonth == 9) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '09'
      }
    } else if (getMonth == 10) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '12'
      }
    } else if (getMonth == 11) {
      if (getDate > 26) {
        month = '12'
      } else {
        month = '12'
      }
    } else if (getMonth == 12) {
      if (getDate > 26) {
        month = '03'
        year = Number(now.getFullYear()) + 1
      } else {
        month = '12'
      }
    }
  }
  var day = year + '-' + month + "-" + date
  return day;
}
// export function getQuarterMonth(type) {
//   var now = new Date();
//   var nowMonth = now.getMonth();
//   var year = now.getFullYear();
//   var quarterStartMonth = "12";
//   if (nowMonth < 3) {
//     quarterStartMonth = "12";
//   }
//   if (2 < nowMonth && nowMonth < 6) {
//     quarterStartMonth = "03";
//   }
//   if (5 < nowMonth && nowMonth < 9) {
//     quarterStartMonth = "06";
//   }
//   if (nowMonth > 8) {
//     quarterStartMonth = "09";
//   }
//   var startDay = year + "-" + quarterStartMonth + "-27";
//   var endDay = null;
//   if (quarterStartMonth == "12") {
//     endDay = year + "-03" + "-26";
//   }
//   if (quarterStartMonth == "09") {
//     endDay = year + "-12" + "-26";
//   }
//   if (quarterStartMonth == "03") {
//     endDay = year + "-06" + "-26";
//   }
//   if (quarterStartMonth == "06") {
//     endDay = year + "-09" + "-26";
//   }
//   var day = "";
//   if (type == "s") {
//     day = startDay;
//   } else {
//     day = endDay;
//   }
//   return day;
// }
// 日期格式化
export function parseTime(time, pattern) {
  if (arguments.length === 0 || !time) {
    return null
  }
  const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
      time = parseInt(time)
    } else if (typeof time === 'string') {
      time = time.replace(new RegExp(/-/gm), '/');
    }
    if ((typeof time === 'number') && (time.toString().length === 10)) {
      time = time * 1000
    }
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
    let value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') {
      return ['日', '一', '二', '三', '四', '五', '六'][value]
    }
    if (result.length > 0 && value < 10) {
      value = '0' + value
    }
    return value || 0
  })
  return time_str
}

// 表单重置
export function resetForm(refName) {
  if (this.$refs[refName]) {
    this.$refs[refName].resetFields();
  }
}

// 添加日期范围
export function addDateRange(params, dateRange, propName) {
  var search = params;
  search.params = {};
  if (null != dateRange && '' != dateRange) {
    if (typeof (propName) === "undefined") {
      search.params["beginTime"] = dateRange[0];
      search.params["endTime"] = dateRange[1];
    } else {
      search.params["begin" + propName] = dateRange[0];
      search.params["end" + propName] = dateRange[1];
    }
  }
  return search;
}

// 回显数据字典
export function selectDictLabel(datas, value) {
  var actions = [];
  Object.keys(datas).some((key) => {
    if (datas[key].dictValue == ('' + value)) {

      actions.push(datas[key].dictLabel);
      return true;
    }
  })
  return actions.join('');
}

// 回显数据字典（字符串数组）
export function selectDictLabels(datas, value, separator) {
  var actions = [];
  var currentSeparator = undefined === separator ? "," : separator;
  var temp = value.split(currentSeparator);
  Object.keys(value.split(currentSeparator)).some((val) => {
    Object.keys(datas).some((key) => {
      if (datas[key].dictValue == ('' + temp[val])) {
        actions.push(datas[key].dictLabel + currentSeparator);
      }
    })
  })
  return actions.join('').substring(0, actions.join('').length - 1);
}

// 通用下载方法
export function download(fileName) {
  window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
}

// 字符串格式化(%s )
export function sprintf(str) {
  var args = arguments,
    flag = true,
    i = 1;
  str = str.replace(/%s/g, function () {
    var arg = args[i++];
    if (typeof arg === 'undefined') {
      flag = false;
      return '';
    }
    return arg;
  });
  return flag ? str : '';
}

// 转换字符串，undefined,null等转化为""
export function praseStrEmpty(str) {
  if (!str || str == "undefined" || str == "null") {
    return "";
  }
  return str;
}

/**
 * 构造树型结构数据
 * @param {*} data 数据源
 * @param {*} id id字段 默认 'id'
 * @param {*} parentId 父节点字段 默认 'parentId'
 * @param {*} children 孩子节点字段 默认 'children'
 */
export function handleTree(data, id, parentId, children) {
  let config = {
    id: id || 'id',
    parentId: parentId || 'parentId',
    childrenList: children || 'children'
  };

  var childrenListMap = {};
  var nodeIds = {};
  var tree = [];

  for (let d of data) {
    let parentId = d[config.parentId];
    if (childrenListMap[parentId] == null) {
      childrenListMap[parentId] = [];
    }
    nodeIds[d[config.id]] = d;
    childrenListMap[parentId].push(d);
  }

  for (let d of data) {
    let parentId = d[config.parentId];
    if (nodeIds[parentId] == null) {
      tree.push(d);
    }
  }

  for (let t of tree) {
    adaptToChildrenList(t);
  }

  function adaptToChildrenList(o) {
    if (childrenListMap[o[config.id]] !== null) {
      o[config.childrenList] = childrenListMap[o[config.id]];
    }
    if (o[config.childrenList]) {
      for (let c of o[config.childrenList]) {
        adaptToChildrenList(c);
      }
    }
  }
  return tree;
}
export function serveGetMonth(val, type) {
  // console.log(date)
  let year = val.substr(0, 4)
  let months = val.substr(5, 2)
  let month = '01'
  let date = 27

  if (type == 's') {
    if (months == '01') {
      month = '12'
      year = year - 1
    } else if (months == '02') {
      month = '01'
    } else if (months == '03') {
      month = '02'

    } else if (months == '04') {
      month = '03'

    } else if (months == '05') {
      month = '04'

    } else if (months == '06') {
      month = '05'

    } else if (months == '07') {
      month = '06'

    } else if (months == '08') {
      month = '07'

    } else if (months == '09') {
      month = '08'

    } else if (months == '10') {
      month = '09'

    } else if (months == '11') {
      month = '10'

    } else if (months == '12') {
      month = '11'
    }
  } else {
    month = months
  }

  if (type == 's') {
    date = 27
  } else {
    date = 26
  }
  // console.log( year + '-' + month + '-' + date)
  var day = year + '-' + month + '-' + date
  return day;
}
//获取前N天的数据
export function getCustomizeDay(num) {
  let number = 30
  if(num){
    number=num
  }
  var date1 = new Date();
  var date2 = new Date(date1);

  //-30为30天前，+30可以获得30天后的日期
  date2.setDate(date1.getDate() - number);

  //30天前（月份判断是否小于10，小于10的前面+0）
  var agoDay = `${date2.getFullYear()}-${
    date2.getMonth() + 1 < 10
      ? `0${date2.getMonth() + 1}`
      : date2.getMonth() + 1
  }-${
    date2.getDate() < 10
      ? `0${date2.getDate() }`
      : date2.getDate()
  }`;

  //当前日期
  var nowDay = `${date1.getFullYear()}-${
    date1.getMonth() + 1 < 10
      ? `0${date1.getMonth() + 1}`
      : date1.getMonth() + 1
  }-${
    date1.getDate() < 10
      ? `0${date1.getDate()}`
      : date1.getDate()
  }`;
  return [agoDay,nowDay]
}
/**
 * 参数处理
 * @param {*} params  参数
 */
export function tansParams(params) {
  let result = ''
  Object.keys(params).forEach((key) => {
    if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) {
      result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&'
    }
  })
  return result
}
